package eu.whowie.bluecontrol.player;

import java.io.IOException;

public class Vlc {

	private VlcHandler vlc = null;

	public Vlc() {

	}

	public void init() throws Exception {
		String[] cmd = getStartCmd();
		try {
			vlc = new VlcHandler(cmd);
		} catch (IOException e) {
			throw new Exception("can't start vlc with cmd: " + cmd, e);
		}
	}

	private String[] getStartCmd() {
		String os = System.getProperty("os.name");
		System.out.println(os);
		if (os.toLowerCase().startsWith("mac")) {
			String[] reti = { "/Applications/VLC.app/Contents/MacOS/VLC",
					"-Ioldrc" };
			// String[] reti = { "/Users/pavel/bin/vlc_wrapper.sh" };
			return reti;
		}
		if (os.toLowerCase().indexOf("linux") != -1) {
			String[] reti = { "/usr/bin/vlc", "-Irc" };
			return reti;
		}
		return null;
	}

	private void shutdown() {
		vlc.shutdown();

	}

	private void test() {

		vlc.test();
	}

	private boolean isShuttedDown() {
		return vlc.isShuttedDown();
	}

	private String getStatus() {
		return vlc.getStatus();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Vlc vlc = new Vlc();
		try {
			vlc.init();
		} catch (Exception e) {
			System.out.println("cant start vlc; " + e.getMessage());
			e.printStackTrace();
		}

		try {

			Thread.sleep(3000);
			System.out.println("vlc status!" + vlc.getStatus());
			vlc.shutdown();
			Thread.sleep(3000);
			if (!vlc.isShuttedDown()) {
				System.out.println("vlc is not shutdown!" + vlc.getStatus());
				System.exit(1);
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
